package com.herench.bs.handler;

import com.herench.bs.agent.IPersonAgent;
import com.herench.bs.annotation.Handler;
import com.herench.bs.support.AbstractMessageHandler;
import com.herench.bs.support.RequestMessage;
import com.herench.bs.support.ResponseMessage;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;

import java.util.Map;


/**
 * com.herench.bs.handler
 * Created by wenkai on 2017/08/31/10:41
 */
@Component
@Handler(code = "100207",name="获取就诊卡列表")
public class TreatmentCardListHandler extends AbstractMessageHandler {
    @Override
    protected ResponseMessage innerHandler(RequestMessage requestMessage) throws Exception {
        ResponseMessage responseMessage = null;
        String channelCode = requestMessage.getArgsPropertyStringValue("sysCode");
        String personId = requestMessage.getArgsPropertyStringValue("psnId");
        String selfFlag = requestMessage.getArgsPropertyStringValue("selfFlag");

        Assert.isTrue(StringUtils.hasLength(channelCode), "sysCode 不能为空！");
        Assert.isTrue(StringUtils.hasLength(personId), "username 不能为空！");
        Assert.isTrue(StringUtils.hasLength(selfFlag), "selfFlag 不能为空！");

        IPersonAgent personAgent = getCleverClinicContext().getApplicationContext().getBean(IPersonAgent.class);
        Map<String,Object> res = personAgent.loadTreatmentCard(personId);
        responseMessage = new ResponseMessage(requestMessage.getId());
        responseMessage.setData(res);
        getPropertiesFromInvokerResultMap(responseMessage,res);
        return responseMessage;
    }
}
